<?php

namespace App\Jobs\Plane\PlaneOrder;

use App\Models\Plane\PlaneOrders\PlaneOrder;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessAfterPlaneOrderChangingWaitingConfirmPrice implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public int         $retry = 1;
    private PlaneOrder $order;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(PlaneOrder $order)
    {
        $this->order = $order;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws Exception
     */
    public function handle()
    {
        // 如果是价格待确认
        if (!$this->order->isProviderPriceConfirmed()) {
            // 这里需要根据乘客处理 , 部分乘客可能需要确认价格 此处需要现将待确认的提交 获得价格后
            // 更新金额支付后和已确认的一起提交
            $service = $this->order->OrderStrategy();
            $service->change_apply($this->order);
        }
    }

    /**
     * 任务的唯一 ID。
     *
     * @return string
     */
    public function uniqueId()
    {
        return $this->order->getOrderSn();
    }
}
